function openAddModuleDialog() {
    openDlg("dlg","模块对话框");
}

function closeModuleDlg() {
    initFormData("fm");
    closeDlgData("dlg");
}

function searchModuleByParams() {
    $("#dg").datagrid("load",{
        moduleName:$("#moduleName").val(),
        optValue:$("#optValue").val(),
        grade:$("#grade").combobox("getValue")
    })
}

function formatterGrade(val) {
    if(val==0){
        return "根级";
    }
    if(val==1){
        return "一级";
    }
    if(val==2){
        return "二级";
    }
}

function openModifyModuleDialog() {
    openModifyDlg("dg", "fm", "dlg", "修改模块信息");
}

function saveOrUpdateModule() {
    var submitUrl = ctx+"saveModule";
    var id = $("#id").val();
    if(!isEmpty(id)){
        submitUrl = ctx+"updateModule";
    }

    saveOrUpdate("fm", submitUrl, "dlg", searchModuleByParams);
}

function deleteModule() {
    deleteData("dg", "deleteModule", searchModuleByParams)
}

$(function(){
    $("#par").hide();
    $("#grade02").combobox({
        onChange:function(newValue){
            if(newValue!=0){
                $("#par").show();
                loadParentModulesByGrade(newValue-1);
            }else{
                /**
                 * 隐藏下拉框
                 */

                $("#par").hide();
                $("#parentId").combobox("clear");
            }
        }
    })
})

function loadParentModulesByGrade(grade) {
    $("#parentId").combobox({
        url:ctx+"queryModulesByGrade?grade="+grade,
        valueField:"id",
        textField:"moduleName",
        panelHeight:"auto"
    })
}